<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    @import "link.html"

</head>
<body>
<div class="">
    <div class="form">
        <form id="ff" class="form-inline" method="get">
            <div class="item-box">
                <p class="item-box-title">基本信息</p>
                <div class="input-item clear-fix">
                    <label>
                        <em>预算单位：</em>
                        <input id="choose-ipt" class="easyui-validatebox easyui-textbox" name="name" data-options="required:true" readonly/>
                        <a id="choose" href="javascript:" class="easyui-linkbutton" data-options="plain:true,iconCls:'fa fa-search'">选择</a>
                        <a id="clear" href="javascript:" class="easyui-linkbutton" data-options="plain:true,iconCls:'fa fa-refresh'">清空</a>
                    </label>
                </div>
                <div class="input-item">
                    <label>
                        <em>上级项目：</em>
                        <select id="father" style="width:135px"></select>
                        <!--<span class="tip-txt">仅可选择可作为父级项目的项目</span>-->
                    </label>
                    <label>
                        <em>项目名称：</em>
                        <input class="easyui-textbox" name="pro_name" data-options="required:true" />
                        <span class="tip-txt">必填项</span>
                    </label>
                </div>
            </div>
            <div class="item-box">
                <p class="item-box-title">系统信息</p>
                <div class="input-item">
                    <label>
                        <em>是否父级：</em>
                        <select id="is-father" class="easyui-combobox" style="width:100px;" name="fa_dept"></select>
                        <span class="tip-txt">一旦确定，不可更改</span>
                    </label>
                    <label>
                        <em>年度：</em>
                        <input id="year" class="easyui-numberspinner" style="width:100px;">
                    </label>
                </div>
                <div class="input-item">
                    <label>
                        <em>项目名称：</em>
                        <input class="easyui-textbox" name="pro_name" data-options="required:true" />
                        <span class="tip-txt">必填项</span>
                    </label>
                    <label>
                        <em>备注：</em>
                        <input class="easyui-textbox" data-options="multiline:true" style="width:200px;height:60px">
                        <!--<span class="tip-txt">非必填项，项目的其他必要说明</span>-->
                    </label>
                </div>
            </div>
            <input id="submit-btn" type="submit" hidden>
        </form>
    </div>
</div>

<script>
  $(function () {
    //上级项目
    $('#father').combobox({
      valueField: 'id',
      textField: 'text',
      // required:true,
      panelHeight:250,
      data:[{
        "id": 11,
        "text": "党政办"
      }, {
        "id": 12,
        "text": "社会事务办"
      }, {
        "id": 13,
        "text": "经发办"
      }, {
        "id": 14,
        "text": "综治办"
      }, {
        "id": 15,
        "text": "城建办"
      }, {
        "id": 16,
        "text": "综合指挥室"
      }, {
        "id": 17,
        "text": "城管中队"
      }, {
        "id": 18,
        "text": "环卫站"
      }, {
        "id": 19,
        "text": "消防队"
      }, {
        "id": 20,
        "text": "交通协管"
      }],
      filter:function (q,row) {
        var opts = $(this).combobox('options');
        return row[opts.textField].indexOf(q) >= 0;
      }
    });
    //是否父级
    $.extend($.fn.validatebox.defaults.rules, {
      choose: {
        validator: function(value){
          return value!='请选择';
        },
        message: '该输入项为必填项'
      }
    });
    $('#is-father').combobox({
      valueField: 'val',
      textField: 'text',
      editable:false,
      panelHeight:'auto',
      validType:'choose',
      data:[{
        val: '',
        text: '请选择'
      },{
        val: '1',
        text: '是'
      },{
        val: '2',
        text: "否"
      }]
    });
    // 年度
    var year=new Date().getFullYear();
    $('#year').numberspinner({
      min: year-5,
      max: year+5,
      value:year,
      required:true
    });
    // 表单提交验证
    var loading=0;
    $('#ff').form({
      url: '../assets/json/area.json',
      onSubmit: function () {
        var isValid = $(this).form('validate');
        if (isValid) {
          loading=layer.load(1);
        }
        return isValid;
      },
      success: function (res) {
        var data=1;
        if(data===1){ //假设等于1是成功
          layer.close(loading);
          layer.msg('提交成功', {
            icon: 6,
            time: 1000
          }, function(){
            dialogClose();
            var ind=parent.$('#tt').find('.tabs-selected').index(),
              win=parent.$('#tt').find('.panel').eq(ind).find('iframe')[0].contentWindow;
            win.reloadDG();
          });
        }else {
          layer.close(loading);
          layer.msg('提交失败，请稍后重试',{icon:'2',anim:'6'}, function(){
            console.log('失败');
          });
        }
      }
    });

    // 编辑时候，父页面传入已有值
    function setVal(obj) {
      $('#ff').form('load',obj);
    }
    window.setVal=setVal;

    // 选择按钮
    $('#choose').on('click',function () {
      parent.iframeShow('单位列表','../y-page/datagrid-add-tree.html',[500,400],{
        btn:['确定','取消'],
        yes:function (index,dom) {
          var ifrBody = dom.find('iframe').contents();
          var nodeObj=ifrBody.find('#choose-node-obj').attr('text');
          if(nodeObj){
            $('#choose-ipt').textbox('setValue',nodeObj);
            parent.layer.close(index);
          }
        }
      });
    });
    // 清空按钮
    $('#clear').on('click',function () {
      $('#choose-ipt').textbox('setValue','');
    });
  });
</script>
</body>

</html>